package org.codegallery.javagal.concurrent.jcip;

import java.io.IOException;
import java.math.BigInteger;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import net.jcip.annotations.GuardedBy;

public class SynchronizedFactorizer implements Servlet{
	@GuardedBy("this") private BigInteger lastNumber;
    @GuardedBy("this") private BigInteger[] lastFactors;

	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		
	}

	public ServletConfig getServletConfig() {
		// TODO Auto-generated method stub
		return null;
	}

	public synchronized void service(ServletRequest req, ServletResponse res)
			throws ServletException, IOException {
		BigInteger i = BigInteger.valueOf(0);
        if (i.equals(lastNumber)){
        	 //do something
        }else {
        	BigInteger[] factors=new BigInteger[]{}; 
        	lastNumber = i;
            lastFactors = factors;
        }
		
	}

	public String getServletInfo() {
		// TODO Auto-generated method stub
		return null;
	}

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

}
